import baseUrl from '@/utils/baseUrl.js' // api接口地址
export default {
  data() {
    return {
      background: {
        backgroundColor: 'rgb(67, 70, 103)',
      },
      shareInfo: {}, //邀请信息
      percent: 0, //进度
      invitationCode: '',
      url: '',
      show: false,
      type: true,//是否显示刻度
      goLink: ''
    }
  },
  onLoad(op){
    if(!op.type)return false
    if(op.type==='push'){
      this.type = false
    }

  },
  created() {
    this.getUserShareInfo()
    this.getCurrentUsersInviteCode()
  },
  //分享给微信好友
  onShareAppMessage: function () {
    let url='/pages_userModule/distriBution/distriBution?code='+ this.invitationCode
    return {
      title: '在吗？100%纯羊毛等你来薅哟~',
      imageUrl: 'https://files.yzsheng.com/client/weixin/fuli.jpg',
      path: url
    }
  },
  methods: {
    lxr() {
		  uni.navigateTo({
		    url: '/pages_userModule/mobileContacts/mobileContacts?inviteCode=' + this.invitationCode
		  })
    },
    async getCurrentUsersInviteCode() {
      try {
        const res = await this.$api.me.getCurrentUsersInviteCode()
        this.invitationCode = res.data
        if (baseUrl === 'https://testapi.yzsheng.com') {
				  this.goLink = `https://files.yzsheng.com/shareH5/Qmc_Client_H5/index.html?code=${this.invitationCode}&judgeurl=0`
        } else if (baseUrl === 'https://lineapi.yzsheng.com') {
				  this.goLink = `https://files.yzsheng.com/shareH5/Qmc_Client_H5/index.html?code=${this.invitationCode}&judgeurl=1`
        }
      } catch (e) {
        //TODO handle the exception
      }
    },
    goStrategy(url) {
      uni.navigateTo({
        url: url
      })
    },

    //跳转落地页
    goPage(type) {
      console.log(this.goLink)
      if(type === 'WXSceneSession' || type==='WXSenceTimeline'){
        let code = this.invitationCode
        uni.share({
				  provider: 'weixin',
				  scene: type,
				  type: 0,
				  summary: '送1000元购车抵用券+39元免费洗车券！点击领取吧',
				  title: '在吗？送你1000元购车抵用券',
				  href: this.goLink,
				  imageUrl: 'https://files.yzsheng.com/client/me/img/logo.png',
				  success: function(res) {
				    console.log(res)
				  },
				  fail: function(err) {
				    console.log('fail:', err)
				    uni.showToast({
				      title: '分享失败'
				    })
				  }
        })
      }
      // console.log(code)
      console.log(type)
    },
    //邀请
    async getUserShareInfo() {
      try {
        const res = await this.$api.me.getUserShareInfo()
        this.shareInfo = res.data

        //判断邀请人数是否超过25人
        if (res.data.shareCount > 25) {
          this.percent = 25 * 4
        } else {
          this.percent = res.data.shareCount * 4
        }
        console.log(res.data)
      } catch (err) {}
    },
  }
}
